const app = getApp()
Page({
    data: {
        content: '自定义toast组件',
        title: '',
        courseId: '',
        iconfont: '',
        isHide: false,
        CourseGrade: [{
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },
            {
                "value": 1
            },

        ]
    },
    onLoad: function(options) {

        var pages = getCurrentPages()
        var _this = this;
        _this.setData({
            tokenID: app.data.tokenID,
            title: options.title,
            courseId: options.sysid
        })
    },
    evaluation: function(event) {
        var _this = this,
            index = event.currentTarget.dataset.index,
            sliderValue = event.detail.value,
            CourseGradeJson = _this.data.CourseGrade;
        CourseGradeJson[index].value = sliderValue;
        _this.setData({
            CourseGrade: CourseGradeJson
        })
    },
    layerMsg: function(msgtype, msg, iconfont) {
        let $this = this;
        if (msgtype == true) {
            $this.setData({
                isHide: msgtype,
                content: msg,
                iconfont: iconfont
            })
            setTimeout(function() {
                $this.setData({
                    isHide: false
                })
            }, 2000)
        } else {}
    },
    submit: function() {
        var _this = this,
            json = {};
        json.courseId = _this.data.courseId
        json.comment1 = _this.data.CourseGrade[0].value,
            json.comment1 = _this.data.CourseGrade[0].value,
            json.comment2 = _this.data.CourseGrade[1].value,
            json.comment3 = _this.data.CourseGrade[2].value,
            json.comment4 = _this.data.CourseGrade[3].value,
            json.comment5 = _this.data.CourseGrade[4].value,
            json.comment6 = _this.data.CourseGrade[5].value,
            json.comment7 = _this.data.CourseGrade[6].value,
            json.comment8 = _this.data.CourseGrade[7].value,
            json.comment9 = _this.data.CourseGrade[8].value,
            json.comment10 = _this.data.CourseGrade[9].value,
            json.comment11 = _this.data.CourseGrade[10].value,
            json.comment12 = _this.data.CourseGrade[11].value;
        wx.request({
            url: app.data.api + 'Curriculum/saveCourseCommentInfo',
            data: {
                "obj": JSON.stringify(json),
                "token": _this.data.tokenID
            },
            method: "POST",
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: function(res) {
                if (res.data.status) {
                    _this.layerMsg(true, res.data.msg, 'icon-yiwancheng');

                    setTimeout(function() {
                        wx.navigateBack({
                            delta: 2
                        })
                    }, 1000)
                }
            }
        })
    }
})